package hu.fic.weddingstorefinder.db.generatedtable;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import hu.fic.weddingstorefinder.db.Table;

public class GeneratedDress extends Table {
	private static final String LOG_TAG = "GeneratedDress";

	public static final String TAB_NAME = "Dress";

	//variables for DressID
	public static final String COL_DRESSID = "DressID";
	public static final int INT_COL_DRESSID = 0;
	protected Integer filter_DRESSID = null;

	//variables for CustomDressId
	public static final String COL_CUSTOMDRESSID = "CustomDressId";
	public static final int INT_COL_CUSTOMDRESSID = 1;
	protected Integer filter_CUSTOMDRESSID = null;
	protected Integer set_CUSTOMDRESSID = null;
	protected boolean forced_CUSTOMDRESSID = false;

	//variables for DressDesc
	public static final String COL_DRESSDESC = "DressDesc";
	public static final int INT_COL_DRESSDESC = 2;
	protected String filter_DRESSDESC = null;
	protected String set_DRESSDESC = null;
	protected boolean forced_DRESSDESC = false;

	//variables for Currency
	public static final String COL_CURRENCY = "Currency";
	public static final int INT_COL_CURRENCY = 3;
	protected String filter_CURRENCY = null;
	protected String set_CURRENCY = null;
	protected boolean forced_CURRENCY = false;

	//variables for Price
	public static final String COL_PRICE = "Price";
	public static final int INT_COL_PRICE = 4;
	protected Integer filter_PRICE = null;
	protected Integer set_PRICE = null;
	protected boolean forced_PRICE = false;

	//variables for ImageName
	public static final String COL_IMAGENAME = "ImageName";
	public static final int INT_COL_IMAGENAME = 5;
	protected String filter_IMAGENAME = null;
	protected String set_IMAGENAME = null;
	protected boolean forced_IMAGENAME = false;

	//variables for CustomPOIId
	public static final String COL_CUSTOMPOIID = "CustomPOIId";
	public static final int INT_COL_CUSTOMPOIID = 6;
	protected Integer filter_CUSTOMPOIID = null;
	protected Integer set_CUSTOMPOIID = null;
	protected boolean forced_CUSTOMPOIID = false;

	//variables for DressStatus
	public static final String COL_DRESSSTATUS = "DressStatus";
	public static final int INT_COL_DRESSSTATUS = 7;
	protected Integer filter_DRESSSTATUS = null;
	protected Integer set_DRESSSTATUS = null;
	protected boolean forced_DRESSSTATUS = false;

	//variables for IsAvailable
	public static final String COL_ISAVAILABLE = "IsAvailable";
	public static final int INT_COL_ISAVAILABLE = 8;
	protected Integer filter_ISAVAILABLE = null;
	protected Integer set_ISAVAILABLE = null;
	protected boolean forced_ISAVAILABLE = false;

	private boolean loaded = false;

	//constructor
	public GeneratedDress(SQLiteDatabase db, Activity activity) {
		super(db, activity);
	}

	//methods for DressID
	public void setDressID(int p) {
		this.filter_DRESSID = new Integer(p);
	}

	public int getDressID() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_DRESSID);
		} else {
			return this.filter_DRESSID.intValue();
		}
	}

	//methods for CustomDressId
	public void setCustomDressId(int p) {
		this.filter_CUSTOMDRESSID = new Integer(p);
	}

	public int getCustomDressId() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_CUSTOMDRESSID);
		} else {
			return this.filter_CUSTOMDRESSID.intValue();
		}
	}
	public void addCustomDressIdUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_CUSTOMDRESSID = new Integer(p);
		} else {
			throw new Exception("The addCustomDressIdUpdate() cannot be used after load.");
		}
	}
	public void forceCustomDressIdColumn() throws Exception {
		if (!this.loaded) {
			this.forced_CUSTOMDRESSID = true;
		} else {
			throw new Exception("The forcedCustomDressIdColumn() cannot be used after load.");
		}
	}

	//methods for DressDesc
	public void setDressDesc(String p) {
		this.filter_DRESSDESC = p;
	}

	public String getDressDesc() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_DRESSDESC);
		} else {
			return this.filter_DRESSDESC;
		}
	}
	public void addDressDescUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_DRESSDESC = p;
		} else {
			throw new Exception("The addDressDescUpdate() cannot be used after load.");
		}
	}
	public void forceDressDescColumn() throws Exception {
		if (!this.loaded) {
			this.forced_DRESSDESC = true;
		} else {
			throw new Exception("The forcedDressDescColumn() cannot be used after load.");
		}
	}

	//methods for Currency
	public void setCurrency(String p) {
		this.filter_CURRENCY = p;
	}

	public String getCurrency() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_CURRENCY);
		} else {
			return this.filter_CURRENCY;
		}
	}
	public void addCurrencyUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_CURRENCY = p;
		} else {
			throw new Exception("The addCurrencyUpdate() cannot be used after load.");
		}
	}
	public void forceCurrencyColumn() throws Exception {
		if (!this.loaded) {
			this.forced_CURRENCY = true;
		} else {
			throw new Exception("The forcedCurrencyColumn() cannot be used after load.");
		}
	}

	//methods for Price
	public void setPrice(int p) {
		this.filter_PRICE = new Integer(p);
	}

	public int getPrice() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_PRICE);
		} else {
			return this.filter_PRICE.intValue();
		}
	}
	public void addPriceUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_PRICE = new Integer(p);
		} else {
			throw new Exception("The addPriceUpdate() cannot be used after load.");
		}
	}
	public void forcePriceColumn() throws Exception {
		if (!this.loaded) {
			this.forced_PRICE = true;
		} else {
			throw new Exception("The forcedPriceColumn() cannot be used after load.");
		}
	}

	//methods for ImageName
	public void setImageName(String p) {
		this.filter_IMAGENAME = p;
	}

	public String getImageName() {
		if (this.loaded) {
			return this.cursor.getString(INT_COL_IMAGENAME);
		} else {
			return this.filter_IMAGENAME;
		}
	}
	public void addImageNameUpdate(String p) throws Exception {
		if (!this.loaded) {
			this.set_IMAGENAME = p;
		} else {
			throw new Exception("The addImageNameUpdate() cannot be used after load.");
		}
	}
	public void forceImageNameColumn() throws Exception {
		if (!this.loaded) {
			this.forced_IMAGENAME = true;
		} else {
			throw new Exception("The forcedImageNameColumn() cannot be used after load.");
		}
	}

	//methods for CustomPOIId
	public void setCustomPOIId(int p) {
		this.filter_CUSTOMPOIID = new Integer(p);
	}

	public int getCustomPOIId() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_CUSTOMPOIID);
		} else {
			return this.filter_CUSTOMPOIID.intValue();
		}
	}
	public void addCustomPOIIdUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_CUSTOMPOIID = new Integer(p);
		} else {
			throw new Exception("The addCustomPOIIdUpdate() cannot be used after load.");
		}
	}
	public void forceCustomPOIIdColumn() throws Exception {
		if (!this.loaded) {
			this.forced_CUSTOMPOIID = true;
		} else {
			throw new Exception("The forcedCustomPOIIdColumn() cannot be used after load.");
		}
	}

	//methods for DressStatus
	public void setDressStatus(int p) {
		this.filter_DRESSSTATUS = new Integer(p);
	}

	public int getDressStatus() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_DRESSSTATUS);
		} else {
			return this.filter_DRESSSTATUS.intValue();
		}
	}
	public void addDressStatusUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_DRESSSTATUS = new Integer(p);
		} else {
			throw new Exception("The addDressStatusUpdate() cannot be used after load.");
		}
	}
	public void forceDressStatusColumn() throws Exception {
		if (!this.loaded) {
			this.forced_DRESSSTATUS = true;
		} else {
			throw new Exception("The forcedDressStatusColumn() cannot be used after load.");
		}
	}

	//methods for IsAvailable
	public void setIsAvailable(int p) {
		this.filter_ISAVAILABLE = new Integer(p);
	}

	public int getIsAvailable() {
		if (this.loaded) {
			return this.cursor.getInt(INT_COL_ISAVAILABLE);
		} else {
			return this.filter_ISAVAILABLE.intValue();
		}
	}
	public void addIsAvailableUpdate(int p) throws Exception {
		if (!this.loaded) {
			this.set_ISAVAILABLE = new Integer(p);
		} else {
			throw new Exception("The addIsAvailableUpdate() cannot be used after load.");
		}
	}
	public void forceIsAvailableColumn() throws Exception {
		if (!this.loaded) {
			this.forced_ISAVAILABLE = true;
		} else {
			throw new Exception("The forcedIsAvailableColumn() cannot be used after load.");
		}
	}

	public void loadAll() throws Exception {
		load();
	}

	public void load(String sql) throws Exception {
		this.loaded = true;
		super.load(sql);
	}

	public void load() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);

		sql.addIntFilter(COL_DRESSID, this.filter_DRESSID);
		if (!this.forced_CUSTOMDRESSID || this.filter_CUSTOMDRESSID != null) {
			sql.addIntFilter(COL_CUSTOMDRESSID, this.filter_CUSTOMDRESSID);
		} else {
			sql.addNullFilter(COL_CUSTOMDRESSID);
		}
		if (!this.forced_DRESSDESC || this.filter_DRESSDESC != null) {
			sql.addStrFilter(COL_DRESSDESC, this.filter_DRESSDESC);
		} else {
			sql.addNullFilter(COL_DRESSDESC);
		}
		if (!this.forced_CURRENCY || this.filter_CURRENCY != null) {
			sql.addStrFilter(COL_CURRENCY, this.filter_CURRENCY);
		} else {
			sql.addNullFilter(COL_CURRENCY);
		}
		if (!this.forced_PRICE || this.filter_PRICE != null) {
			sql.addIntFilter(COL_PRICE, this.filter_PRICE);
		} else {
			sql.addNullFilter(COL_PRICE);
		}
		if (!this.forced_IMAGENAME || this.filter_IMAGENAME != null) {
			sql.addStrFilter(COL_IMAGENAME, this.filter_IMAGENAME);
		} else {
			sql.addNullFilter(COL_IMAGENAME);
		}
		if (!this.forced_CUSTOMPOIID || this.filter_CUSTOMPOIID != null) {
			sql.addIntFilter(COL_CUSTOMPOIID, this.filter_CUSTOMPOIID);
		} else {
			sql.addNullFilter(COL_CUSTOMPOIID);
		}
		if (!this.forced_DRESSSTATUS || this.filter_DRESSSTATUS != null) {
			sql.addIntFilter(COL_DRESSSTATUS, this.filter_DRESSSTATUS);
		} else {
			sql.addNullFilter(COL_DRESSSTATUS);
		}
		if (!this.forced_ISAVAILABLE || this.filter_ISAVAILABLE != null) {
			sql.addIntFilter(COL_ISAVAILABLE, this.filter_ISAVAILABLE);
		} else {
			sql.addNullFilter(COL_ISAVAILABLE);
		}

		sql.addTail(" ORDER BY " + COL_DRESSID);
		load(sql.getSql());
	}

	public void clear() {
		this.filter_DRESSID = null;

		this.filter_CUSTOMDRESSID = null;
		this.set_CUSTOMDRESSID = null;
		this.forced_CUSTOMDRESSID = false;

		this.filter_DRESSDESC = null;
		this.set_DRESSDESC = null;
		this.forced_DRESSDESC = false;

		this.filter_CURRENCY = null;
		this.set_CURRENCY = null;
		this.forced_CURRENCY = false;

		this.filter_PRICE = null;
		this.set_PRICE = null;
		this.forced_PRICE = false;

		this.filter_IMAGENAME = null;
		this.set_IMAGENAME = null;
		this.forced_IMAGENAME = false;

		this.filter_CUSTOMPOIID = null;
		this.set_CUSTOMPOIID = null;
		this.forced_CUSTOMPOIID = false;

		this.filter_DRESSSTATUS = null;
		this.set_DRESSSTATUS = null;
		this.forced_DRESSSTATUS = false;

		this.filter_ISAVAILABLE = null;
		this.set_ISAVAILABLE = null;
		this.forced_ISAVAILABLE = false;

		this.loaded = false;
		super.clear();
	}

	public long newRow() throws Exception {
		try {
			ContentValues newTaskValues = new ContentValues();
			newTaskValues.put(COL_CUSTOMDRESSID, filter_CUSTOMDRESSID);
			newTaskValues.put(COL_DRESSDESC, filter_DRESSDESC);
			newTaskValues.put(COL_CURRENCY, filter_CURRENCY);
			newTaskValues.put(COL_PRICE, filter_PRICE);
			newTaskValues.put(COL_IMAGENAME, filter_IMAGENAME);
			newTaskValues.put(COL_CUSTOMPOIID, filter_CUSTOMPOIID);
			newTaskValues.put(COL_DRESSSTATUS, filter_DRESSSTATUS);
			newTaskValues.put(COL_ISAVAILABLE, filter_ISAVAILABLE);
			return this.db.insert(TAB_NAME, null, newTaskValues);
		} catch (Exception e) {
			Log.e(LOG_TAG, "Cannot execute inserting (" + e.getMessage() + ")", e);
			throw new Exception("Insert failed, see log file for details!");
		}
	}

	public void delete() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);
		sql.addIntFilter(COL_DRESSID, this.filter_DRESSID);
		sql.addIntFilter(COL_CUSTOMDRESSID, this.filter_CUSTOMDRESSID);
		sql.addStrFilter(COL_DRESSDESC, this.filter_DRESSDESC);
		sql.addStrFilter(COL_CURRENCY, this.filter_CURRENCY);
		sql.addIntFilter(COL_PRICE, this.filter_PRICE);
		sql.addStrFilter(COL_IMAGENAME, this.filter_IMAGENAME);
		sql.addIntFilter(COL_CUSTOMPOIID, this.filter_CUSTOMPOIID);
		sql.addIntFilter(COL_DRESSSTATUS, this.filter_DRESSSTATUS);
		sql.addIntFilter(COL_ISAVAILABLE, this.filter_ISAVAILABLE);
		this.db.execSQL(sql.getDeleteSql());
	}

	public void deleteAllRows() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);
		this.db.execSQL(sql.getDeleteAllSql());
	}

	public void update() throws Exception {
		SQLStatement sql = new SQLStatement();
		sql.addTable(TAB_NAME);

		sql.addIntFilter(COL_DRESSID, this.filter_DRESSID);

		sql.addIntFilter(COL_CUSTOMDRESSID, this.filter_CUSTOMDRESSID);
		sql.addIntSet(COL_CUSTOMDRESSID, this.set_CUSTOMDRESSID);

		sql.addStrFilter(COL_DRESSDESC, this.filter_DRESSDESC);
		sql.addStringSet(COL_DRESSDESC, this.set_DRESSDESC);

		sql.addStrFilter(COL_CURRENCY, this.filter_CURRENCY);
		sql.addStringSet(COL_CURRENCY, this.set_CURRENCY);

		sql.addIntFilter(COL_PRICE, this.filter_PRICE);
		sql.addIntSet(COL_PRICE, this.set_PRICE);

		sql.addStrFilter(COL_IMAGENAME, this.filter_IMAGENAME);
		sql.addStringSet(COL_IMAGENAME, this.set_IMAGENAME);

		sql.addIntFilter(COL_CUSTOMPOIID, this.filter_CUSTOMPOIID);
		sql.addIntSet(COL_CUSTOMPOIID, this.set_CUSTOMPOIID);

		sql.addIntFilter(COL_DRESSSTATUS, this.filter_DRESSSTATUS);
		sql.addIntSet(COL_DRESSSTATUS, this.set_DRESSSTATUS);

		sql.addIntFilter(COL_ISAVAILABLE, this.filter_ISAVAILABLE);
		sql.addIntSet(COL_ISAVAILABLE, this.set_ISAVAILABLE);

		this.db.execSQL(sql.getUpdateSql());
	}

}